package com.my.yyr.service.safty.impl;

import com.my.yyr.base.CurrUser;
import com.my.yyr.dao.safty.LoginDao;
import com.my.yyr.dto.UserDto;
import com.my.yyr.exception.BusinessException;
import com.my.yyr.exception.SysException;
import com.my.yyr.model.User;
import com.my.yyr.service.safty.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service @Transactional
public class LoginServiceImpl implements LoginService {

    private LoginDao loginDao;


    @Autowired
    public void setLoginDao(LoginDao loginDao){
        this.loginDao=loginDao;
    }



    @Override
    public CurrUser checkLogin(UserDto userDto) throws BusinessException, SysException {

        User user = null;
        try {
            user = loginDao.findUserByUserIdAndPwd(userDto);
        } catch (Exception e) {
           throw new SysException(e);
        }

        if(user==null){
            throw new BusinessException("账号或者密码错误");
        }
        return new CurrUser(user.getU_id(),user.getU_name());
    }
}
